//
//  YLRegisterViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/8/13.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "YLRegisterViewController.h"
#import "VerificationCodeBtn.h"
@interface YLRegisterViewController ()
@property (weak, nonatomic) IBOutlet UIView *topV;
@property (weak, nonatomic) IBOutlet UIView *bottomV;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTf;
@property (weak, nonatomic) IBOutlet VerificationCodeBtn *codeBtn;
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;

@end

@implementation YLRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setCorder:self.topV];
    [self setCorder:self.bottomV];
    [self setCorder:self.registerBtn];
    // Do any additional setup after loading the view from its nib.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"注册";
    self.view.backgroundColor = [UIColor whiteColor];
    self.codeBtn.layer.cornerRadius = 15;
    self.codeBtn.layer.masksToBounds = YES;
    WS(weakSelf)
    [self.codeBtn addTarget:self action:@selector(startGetVercode:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)startGetVercode:(UIButton *)btn{
    if (![NSString checkTelNumber:self.phoneTF.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入正确的手机号"];
        return;
    }
    [self.codeBtn startTimer];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneTF.text,@"TelCode", nil];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:sendPhoneCode header:nil parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSString *message = responseObject[@"result"][@"message"];
        [SVProgressHUD showInfoWithStatus:@"验证码发送成功"];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(void)setCorder:(UIView *)view{
    view.layer.cornerRadius = 23;
    view.layer.masksToBounds = YES;
    if ([view isKindOfClass:[UIButton class]]) {
        return;
    }
    view.layer.borderWidth = 1;
    view.layer.borderColor = COLOR_HEX(0xE0E0E0).CGColor;
}
- (IBAction)registerAction:(id)sender {
    if ([NSString isBlankString:self.phoneTF.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入手机号"];
        return;
    }
    if ([NSString isBlankString:self.codeTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入验证码"];
        return;
    }
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneTF.text,@"TelCode",self.codeTf.text,@"RadCode", nil];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:comparePhoneCode header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD showInfoWithStatus:@"您的注册申请已经提交，稍后我们会为您配置相关的用户信息并发送至您的注册手机号码，感谢您对银来助手的支持！！！"];
        [self dismissViewControllerAnimated:YES completion:nil];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
